﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PerfumeShopManagement.BLL;
using PerfumeShopManagement.Utility;
using PerfumeShopManagement.Model;

namespace PerfumeShopManagement.View
{
    public partial class frmImportCheckManagement : Form
    {
        private BllImportCheck bllImportCheck = new BllImportCheck();
        private frmImportCheck detailView;

        public frmImportCheckManagement()
        {
            InitializeComponent();
        }

        private void showDetailView(BllImportCheck bllImportCheck)
        {
            detailView = new frmImportCheck(bllImportCheck);
            detailView.Visible = true;
            detailView.FormClosed += new FormClosedEventHandler(detailView_FormClosed);
            this.Enabled = false;
        }

        private void detailView_FormClosed(object sender, FormClosedEventArgs e)
        {
            reloadGridView();
            this.Enabled = true;
        }

        private void addItemForTotalCriteria()
        {
            cbbOperator.Items.Clear();
            cbbOperator.Items.Add(Constants.BIGGER_OR_EQUAL_COMPARISON); // >=
            cbbOperator.Items.Add(Constants.BIGGER_COMPARISON); // >
            cbbOperator.Items.Add(Constants.EQUAL_COMPARISON); // =
            cbbOperator.Items.Add(Constants.SMALLER_COMPARISON); // <
            cbbOperator.Items.Add(Constants.SMALLER_OF_EQUAL_COMPARISON); // <=
        }

        private void resetFormField()
        {
            txbImportCheckId.Text = "";
            dtpMakingDate.Value = DateTime.Now;
            cbbOperator.Text = "";
            txbOperand.Text = "";
        }

        private void reloadGridView()
        {
            // Load grid view
            object[] buffer = new object[5];
            List<DataGridViewRow> rows = new List<DataGridViewRow>();
            List<ImportCheck> importChecks = bllImportCheck.GetAll();
            foreach (ImportCheck item in importChecks)
            {
                buffer[0] = item.ImportCheckId;
                buffer[1] = item.ImportCheckTime;
                buffer[2] = item.Total;

                rows.Add(new DataGridViewRow());
                rows[rows.Count - 1].CreateCells(gridImportChecks, buffer);
            }
            gridImportChecks.Rows.Clear();
            gridImportChecks.Rows.AddRange(rows.ToArray());
        }

        private void frmImportCheckManagement_Load(object sender, EventArgs e)
        {
            addItemForTotalCriteria();
            resetFormField();
            reloadGridView();
        }

        private void btnAddImportCheck_Click(object sender, EventArgs e)
        {
            showDetailView(bllImportCheck);
        }

        private void grbCategoryInfo_Enter(object sender, EventArgs e)
        {

        }
    }
}
